<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<script src="js/mui.min.js"></script>
		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
		<script type="text/javascript" src="js/publicurl.js" ></script>
		<script type="text/javascript" src="js/my.js"></script>
		<link rel="stylesheet" href="css/ymk.css" />
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>

	<body>
		<!--mheader  按下回车键-->
		<header class="mui-bar mui-bar-nav" style="background: dodgerblue;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" style="color: white;">找回密码</h1>
		</header>
		<!--mbody  按下回车键-->
		<div class="mui-content" id="input_example">
			<div class="logo-img">
				<img src="images/logo.png" />
				<div class="denglu-a" style="margin-top: 20px;">
					<div class="denglu-a-l">
						<label>账号</label>
					</div>
					<div class="denglu-a-r">
						<label style=" visibility:hidden;">账号</label>
						<input type="text" id="myphone" placeholder="请输入您的手机号" >
						<button class="zhuce-btn" style="margin-top: 10px;" id="getcode">获取验证码</button>
					</div>
				</div>
				<div class="denglu-a">
					<div class="denglu-a-l">
						<label>验证码</label>
					</div>
					<div class="denglu-a-r">
						<label style=" visibility:hidden;">验证码</label>
						<input type="text" id="checkcode" placeholder="请输入验证码">
					</div>
				</div>
				<div class="denglu-a">
					<div class="denglu-a-l">
						<label>新密码</label>
					</div>
					<div class="denglu-a-r">
						<label style=" visibility:hidden;">新密码</label>
						<input type="password" placeholder="请输入您的密码" id="newpassword">
					</div>
				</div>
				<button class="btn" id="getpassword">找回密码</button>
				<div style="width:90%;margin:0 auto;">
					<button class="mui-btn-link mui-pull-left" style="padding: 0px;" id="login">登录</button>
					<button class="mui-btn-link mui-pull-right" style="padding: 0px;" id="register">注册</button>
				</div>
			</div>
		</div>
		<script>
			mui.init();
			
			var userInfo=JSON.parse(localStorage.getItem("userInfo"));
			var getpass = document.getElementById("getpassword");
			var getcode = document.getElementById("getcode");
			var login=document.getElementById("login");
			var register=document.getElementById("register");
			var input=document.getElementsByTagName("input");
			
			login.addEventListener('tap',function(){
				mui.openWindow({
					url: 'login.html',
					id: 'login'
				})
			});
			register.addEventListener('tap',function(){
				mui.openWindow({
					url:'register.html',
					id:'register'
				})
			})
			var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
			var tm = 60;
			var flag = true;
			var regcode;
			
			getcode.addEventListener('tap', function() {
				var username = $("#myphone").val();
				if(!reg.test(username)) {
					alert("您的手机号不符合规范");
					return;
				}
				$("#getcode").attr("disabled",true);
				if(flag) {
					var timer = setInterval(function() {
						if(tm==60 && flag) {
							flag = false;
							mui.ajax(puburl.url+'/dangxia/phone/getcode', {
								data: {
									"username": username
								},
								dataType: 'json', //服务器返回json格式数据
								type: 'post', //HTTP请求类型
								timeout: 10000, //超时时间设置为10秒；
								success: function(data) {
									var data1 = JSON.parse(data.msg);
									/*验证成功*/
									if(data1.return_code=="00000") {
										mui.alert("发送成功");
										regcode = data.code;
									} else {
										msgtips("<span style='color:red'>发送失败</span>");
										flag = true;
										tm=60;
										clearInterval(timer);
									}
								},
								error: function(xhr, type, errorThrown) { //异常处理；
									console.log(type);
								}
							});
						} else if(tm==0) {
							$("#getcode").attr("disbled",true);
							$("#getcode").html("获取验证码");
							flag=true;
							clearInterval(timer);
							tm=60;
							
						}else{
							$("#getcode").html(tm+"s后重新获取");
							tm--;
						}
					},1000);
				
				}

			});
			getpass.addEventListener('tap', function() {
				
				var username=input[0].value;
				var newpassword=input[2].value;
				mui("#input_example input").each(function() {
					//若当前input为空，则alert提醒 
					if(!this.value || this.value.trim() == "") {
						var label = this.previousElementSibling;
						mui.alert(label.innerHTML + "不允许为空");
						check = false;
						return false;
					}

				});
				if($("#checkcode").val()!=regcode) {
					mui.alert("验证码不正确");
					return;
				}
				mui.ajax(puburl.url+'/dangxia/user/findpassword', {
					data: {
						username: username,
						psw:newpassword
						
					},
					dataType: 'json', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					success: function(data) {
						if(data.code == 0) {
							mui.alert("修改成功，正在跳往登录页面");
							my.jump("login.html","login");

						} else {
							mui.toast(data.msg);
						}

					},
					error: function(xhr, type, errorThrown) { //异常处理；
						console.log(type);
					}
				});

			});
		</script>
	</body>

</html>